package com.weixin.dao;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.weixin.utils.DateUtils;

public class Code extends Model<Code>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Integer day = Integer.valueOf(DateUtils.getDay());
	/**
	 * 查询出验证码对应的城市门店省份信息
	 * @return
	 */
	@SuppressWarnings("unused")
	public Code selectCodeInfo(String code){
		
		int month = DateUtils.getCurrentMonth();
		String c = null; 
		if (month==4) {
			if (day<9) {
				c = "code1";
			}else if(day>8&&day<17){
				c = "code2";
			}else if(day>=17&&day<=24){
				c = "code3";
			}else if(day>=24){
				c = "code4";
			}
		}else {
			c = "code4";
		}
		
		String sql = "SELECT "
				+ " s.`id` AS stoid , store , city ,ci.`id` AS cid ,p.`name` as province, p.id AS pid "
				+ "FROM "
				+ "CODE c "
				+ "JOIN store s "
				+ " ON c.`id` = s.`code_id` "
				+ " JOIN city ci "
				+ " ON ci.`id` = s.`city_id` "
				+ "JOIN province p"
				+ " ON ci.`province_id` = p.`id` "
				+ "WHERE c.`"+c+"` =  "+ code;
		return findFirst(sql);
	}
}
